package com.demo.yang.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.demo.yang.bean.Account;
import com.demo.yang.bean.AccountExample;
import com.demo.yang.bean.AccountExample.Criteria;
import com.demo.yang.dao.AccountDao;
import com.demo.yang.service.AccountService;

@Service("accountService")
public class AccountServiceImpl implements AccountService{
	
	@Resource
	public AccountDao accountDao;
	

	@Override
	public int register(Account account) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Account> getAccountByNo(String accountNo) {
		AccountExample example = new AccountExample();
		Criteria criteria = example.createCriteria();
		criteria.andAccountnoEqualTo(accountNo);
		return accountDao.selectByExample(example);
	}

	@Override
	public int addAccount(Account account) {
		return accountDao.insert(account);
	}

	@Override
	public Account login(String accountNo, String pwd) {
		return accountDao.selectAccountByAccNoAndPwd(accountNo,pwd);
	}

	@Override
	public boolean isExistAccount(String accountNo) {
		AccountExample example = new AccountExample();
		Criteria criteria = example.createCriteria();
		criteria.andAccountnoEqualTo(accountNo);
		long count = accountDao.countByExample(example);
		return count > 0;
	}

}
